#include <stdlib.h>
#include <stdio.h>

#define RECORD_COUNT 4

#define FILE_NAME "work.txt"
#define INPUT_FILE_NAME FILE_NAME
#define OUTPUT_FILE_NAME FILE_NAME

typedef FILE* File;

int main(void) {
  struct {
    char name[8];
    int age;
    int salary;
  } employees[RECORD_COUNT];

  File istream = fopen(INPUT_FILE_NAME, "r");
  if (istream == NULL) {
    fprintf(stderr, "Cannot open %s with r mode.\n", INPUT_FILE_NAME);
    exit(EXIT_FAILURE);
  }
  for (int index = 0; index < RECORD_COUNT; index++) {
    fscanf(istream, "%s%d%d", employees[index].name, &employees[index].age, &employees[index].salary);
    printf("%s %d %d\n", employees[index].name, employees[index].age, employees[index].salary);
    if (employees[index].salary < 30000) {
      employees[index].salary += 3000;
    }
  }
  fclose(istream);

  File ostream = fopen(OUTPUT_FILE_NAME, "w");
  if (ostream == NULL) {
    fprintf(stderr, "Cannot open %s with w mode.\n", OUTPUT_FILE_NAME);
    exit(EXIT_FAILURE);
  }
  for (int index = 0; index < RECORD_COUNT; index++) {
    printf("%s %d %d\n", employees[index].name, employees[index].age, employees[index].salary);
    fprintf(ostream, "%s %d %d\n", employees[index].name, employees[index].age, employees[index].salary);
  }
  fclose(ostream);

  return EXIT_SUCCESS;
}
